package org.jsola.hr.service.excel;

import lombok.extern.slf4j.Slf4j;
import org.jsola.common.BeanKit;
import  org.jsola.hr.dto.GysInfoAddDTO;
import  org.jsola.hr.dto.excel.GysInfoImportDTO;
import  org.jsola.hr.exception.HrException;
import  org.jsola.hr.service.IGysInfoService;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhr
 */
@Slf4j
public class GysInfoImportListener extends BaseAnalysisEventListener<GysInfoImportDTO> {

    /**
     * 入库
     */
    @Override
    public void saveData() {
        log.info("{}条数据，开始存储数据库！", dataList.size());
        if (dataList.size() == 0) {
            log.warn("没有数据需要入库");
            return;
        }
        HrException.notNull(tokenUser, "没有设置当前登录用户");
        List<GysInfoAddDTO> gysInfoList = dataList.stream()
                .map(gysInfoImportDTO -> gysInfoImportDTO.to(GysInfoAddDTO.class))
                .collect(Collectors.toList());
        IGysInfoService gysInfoService = BeanKit.getBean(IGysInfoService.class);
        successCount += gysInfoService.batchSave(gysInfoList,tokenUser).size();
        log.info("存储数据库成功！");
    }

}
